********************************************************************************
********************************************************************************
********************************************************************************
* DENTLER, BLINZLER AND QUINLAN - ELECTORAL MESSIAH OR PARTY LABEL?
* Devised by KB
* Last updated: Wednesday, October 18, 2023
* Apply syntax to 1998-2021 Timeseries Dataset ("1998_2021_timeseries.dta")
* File Created under Stata Version 16.1, Platform: MacOSX
********************************************************************************
********************************************************************************
********************************************************************************

********************************************************************************
********************************************************************************
**>>> SYNTAX FILE TABLE OF CONTENTS
** 1: INSTRUCTIONS FOR USE OF SYNTAX FILE, PURPOSE OF SYNTAX FILE AND STATA SETUP
** 2: VOTER TYPOLOGY VARIABLE FOLLOWING QUINLAN & MCALLISTER
** 3: VOTE CHOICE VARIABLE
** 4: APPENDIX D - SUMMARY STATISTICS
** 5: APPENDIX E - RESULTS TABLES (FOR 1998-2021 TIME SERIES DATA)
** 6: APPENDIX F - ROBUSTNESS CHECKS (FOR 1998-2021 TIME SERIES DATA)
** 7: APPENDIX G - LOGIT MODELS (FOR 1998-2021 TIME SERIES DATA)


********************************************************************************
********************************************************************************

********************************************************************************
********************************************************************************
**#>>> 1: INSTRUCTIONS FOR USE OF SYNTAX FILE, PURPOSE OF SYNTAX FILE
**        AND STATA SETUP
********************************************************************************
********************************************************************************

********************************************************************************
**// INSTRUCTIONS FOR NAVIGATING FILE
********************************************************************************

** #>>> = Section Heading
** //  = Subsection Heading
** <<< = Heading for Code Instruction / Explanation


********************************************************************************
**// PURPOSE INSTRUCTIONS FOR NAVIGATING FILE
********************************************************************************
* This do-file serves to convey all modifications and SUPPLEMENTARY analyses 
* applied to the 1998-2021 Timeseries Dataset, as reported in the APPENDICES of 
* the Dentler, Blinzler and Quinlan paper "ELECTORAL MESSIAH OR PARTY LABEL?
* QUANTIFYING AND INVESTIGATING LEADER-PARTY RELATIONSHIPS IN GERMAN FEDERAL
* ELECTIONS 1998–2021". 



********************************************************************************
**// SETUP STATA 
********************************************************************************

*<<< specify version of Stata used for this session
version 16.1 

*<<< clears the stata session and close all open files, windows & dialoge boxes:
clear all

*<<< mute pause or display --more-- messages in results window:
set more off 

*<<< set maximum scrollback-option for Stata results window:
set scrollbufsize 2000000 


********************************************************************************
**// INSTALL ADD-ONS FOR STATA
********************************************************************************

*<<< Install estout to enable transfers of tables from STATA to Word
ssc install estout, replace
ssc describe estout

*<<< Install fre to enable formatted frequency tables in Stata results window
ssc install fre, replace 
ssc describe fre

*<<< Install fitstat to enable additional goodness of fit measures
ssc install fitstat, replace
ssc describe fitstat


********************************************************************************
**//  LOADING DATA INTO STATA
********************************************************************************

*<<< setting the working directory: 
cd "/Users/katharina/CSES Dropbox/Katharina Blinzler/Dentler_Blinzler_Quinlan_Leader or Party DE/Replication Materials"

*<<< Loading Dataset:
use "./Processed Data/1998_2021_timeseries.dta", clear

*<<< Drop German 2002 studies as leader measures are unavailable for them: 
drop if study_year == 2002


********************************************************************************
********************************************************************************
**#>>> 2: VOTER TYPOLOGY VARIABLE FOLLOWING QUINLAN & MCALLISTER
********************************************************************************
********************************************************************************

*<<< Required variable: 1. Leader inclined, 2. Leader leaning, 3. Party and Leader,
*                       4. Party leaning, 5. Party inclined, 6. Incongruent 

*<<< Recode the existing variable accordingly to reorder groups:
gen typesofvoter_2 = .
replace typesofvoter_2 = 1 if typesofvoter == 1 // Leader inclined voter
replace typesofvoter_2 = 2 if typesofvoter == 5 // Leader leaning voter
replace typesofvoter_2 = 3 if typesofvoter == 3 // Party and leader inclined voter
replace typesofvoter_2 = 4 if typesofvoter == 6 // Party leaning voter
replace typesofvoter_2 = 5 if typesofvoter == 2 // Party inclined voter
replace typesofvoter_2 = 6 if typesofvoter == 4 // Incongruent voter 

tab typesofvoter_2 typesofvoter, m 

*<<< drop the old version of the voter type variable:
drop typesofvoter 

*<<< rename the updated typesofvoter variable:
rename typesofvoter_2 typesofvoter 

*<<< Assign variable and value labels: 
lab var typesofvoter "Types of Voters"
lab def types_lab_2 1 "Leader inclined voter" ///
                  2 "Leader leaning voter" ///
				  3 "Party & leader inclined voter" ///
				  4 "Party leaning voter" ///
				  5 "Party inclined voter" ///
				  6 "Incongruent voter"
lab val typesofvoter types_lab_2 

*<<< add numeric party codes to value labels:
numlabel types_lab_2, add

tab typesofvoter, m


********************************************************************************
********************************************************************************
**#>>> 3: VOTE CHOICE VARIABLE
********************************************************************************
********************************************************************************

*<<< identify multinomial vote choice variable:
tab vote_pl 
fre vote_pl

*<<< generate a new variable where we could drop "Other Party":
gen vote_all = vote_pl

*<<< drop "Other Party" from new vote choice variable:
replace vote_all = .a if vote_all == 801 
tab vote_all, m


********************************************************************************
********************************************************************************
**#>>> 3: APPENDIX D - SUMMARY STATISTICS
********************************************************************************
********************************************************************************

********************************************************************************
**// APPENDIX D - TABLES D1-D6:
********************************************************************************

*<<< Tables D1 - D6 - Vote Choice: 
bysort study_year: tab vote_all, m

* NOTE: "Other Party" set to missing.

*<<< format variables for displaying decimals in tables: 
format vote_* PartyLike* LeaderLike* typesofvoter pid_* lr_* val_eco female age university church_attendance east %14.2f

*<<< Tables D1 - D6 - Other Variables Than Vote Choice:
bysort study_year: sum vote_union vote_spd vote_fdp vote_green vote_left vote_afd PartyLike* LeaderLike* typesofvoter pid_cdu pid_spd pid_fdp pid_green pid_afd lr_self val_eco female age university church_attendance east, format


********************************************************************************
**// APPENDIX D - BAR GRAPHS FOR VOTE CHOICE BY YEAR 
********************************************************************************

*<<< Exporting Bar Plots for Key Categorical Variables - Vote Choice: 

foreach year in 1998 2005 2009 {

*<<< create graphs for 1998 - 2009 (without AfD):
graph bar (count) if study_year == `year', over(vote_pl, sort(1) descending)  asyvars ///
ysize(4) xsize(6) percent ///
bar(1, color(black)) bar(2, color(red)) bar(3, color(yellow)) ///
bar(4, color(green)) bar(5, color(pink)) bar(6, color(gs14)) /// 
blabel(bar, format(%4.1f)) bargap(50) ///
graphregion(color(white)) ///
title("Distribution of Vote Choice Variable in `year' Election" "(Zweitstimme or Party List Vote)") ///
ytitle("Percent of Valid Answers" "(Missing Data Excluded)")

*<<< export graphs for 1998 - 2009:
graph export "./Outputs/Stata Graphs/VoteChoice_`year'.png", as(png) replace
} 
   
foreach year in 2013 2017 2021 {

*<<< create graphs for 2013 - 2021 (AfD included):
graph bar (count) if study_year == `year', over(vote_pl, sort(1) descending)  asyvars ///
ysize(4) xsize(6) percent ///
bar(1, color(black)) bar(2, color(red)) bar(3, color(yellow)) ///
bar(4, color(green)) bar(5, color(pink)) bar(6, color(midblue)) /// 
bar(7, color(gs14)) ///
blabel(bar, format(%4.1f)) bargap(50) ///
graphregion(color(white)) ///
title("Distribution of Vote Choice Variable in `year' Election" "(Zweitstimme or Party List Vote)") ///
ytitle("Percent of Valid Answers" "(Missing Data Excluded)")

*<<< export graphs for 2013 - 2021 (AfD included):
graph export "./Outputs/Stata Graphs/VoteChoice_`year'.png", as(png) replace
} 


********************************************************************************
**// APPENDIX D - BAR GRAPHS FOR VOTER TYPES BY YEAR 
********************************************************************************

*<<< Exporting Bar Plots for Key Categorical Variables - Voter Types: 

foreach year in 1998 2005 2009 2013 2017 2021 {

*<<< create graphs for voter types by election year:
graph bar (count) if study_year == `year', over(typesofvoter) asyvars ///
ysize(4) xsize(6) percent ///
bar(1, color(red)) bar(2, color(sandb)) bar(3, color(blue)) ///
bar(4, color(olive_teal)) bar(5, color(green)) bar(6, color(gs14)) /// 
blabel(bar, format(%4.1f)) bargap(50) ///
graphregion(color(white)) legend(order(1 4 2 5 3 6)) ///
title("Distribution of Voter Types Variable in `year' Election") ///
ytitle("Percent of Valid Answers" "(Missing Data Excluded)")

*<<< export graphs by election year:
graph export "./Outputs/Stata Graphs/VoterTypes_`year'.png", as(png) replace
} 


********************************************************************************
********************************************************************************
**#>>> 4: APPENDIX E - RESULTS TABLES (FOR 1998-2021 TIME SERIES DATA)
********************************************************************************
********************************************************************************


********************************************************************************
**// TABLE E1.1 - MULTINOMIAL LOGIT FOR 2021 ELECTION (BASIS FOR FIGURE 4): 
********************************************************************************

*<<< Table E1.1 - Multinomial logit for 2021 election (basis for Figure 4): 
eststo E11 : mlogit vote_all ib5.typesofvoter female age university church_attendance east lr_self if study_year == 2021 [pweight=sample_weight], baseoutcome(1) // Union as reference

*<<< Create nicely formatted results table & export it to Output folder:
esttab E11 using "./Outputs/Stata Tables/tableE11.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table E1.1) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


*<<< Table E1.2 - Multinomial logit for 2021 election (unweighted): 
eststo E12 : mlogit vote_all ib5.typesofvoter female age university church_attendance east lr_self if study_year == 2021, baseoutcome(1) // Union as reference

*<<< Create nicely formatted results table & export it to Output folder:
esttab E12 using "./Outputs/Stata Tables/tableE12.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table E1.2) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


	   
********************************************************************************
********************************************************************************
**#>>> 5: APPENDIX F - ROBUSTNESS CHECKS (FOR 1998-2021 TIME SERIES DATA)
********************************************************************************
********************************************************************************
	   

********************************************************************************   
**// TABLE F1 - CORRELATION ANALYSIS BETWEEN LEADER AND PARTY POPULARITY SCALES
* (1998 – 2021 TIMESERIES)
********************************************************************************

foreach party in cdu csu spd green fdp left afd {
	* <<< for each party, recode missing values in party & leader popularity scales to .
	replace PartyLike_`party' = . if PartyLike_`party' <0
	replace LeaderLike_`party' = . if LeaderLike_`party' <0
	
	* <<< for each party, run the correlation analyses:
	pwcorr PartyLike_`party' LeaderLike_`party', star(.01)
}


********************************************************************************
**// FIGURE F1 - PARTY-LEADER POPULARITY INDEX WITH REVISED "NEUTRAL" CATEGORY: 
********************************************************************************

*<<< creating a new frame "tricho_rev_totals" that includes the same data as the default frame: 
frame copy default tricho_rev_totals

*<<< switch to "tricho_rev_totals" frame:
frame change tricho_rev_totals


*<<< Creating revised trichotomy for popularity index (5 = neutral): 

***************
* PARTIES:
***************
foreach party in cdu spd green fdp left afd {

*<<< generate revised trichotomy:
recode PartyLike_`party' (0/4 = 0) (5 = 1) (6/10 = 2) (-1 = .), gen(trichotomy_rev_`party')

*<<< label revised trichotomy:
lab var trichotomy_rev_`party' "Party Likeability: `party' (revised trichotomy)"
lab def trichotomy_`party' 0 "Does not like: `party'" ///
                                  1 "Neutral: `party'" ///
								  2 "Likes: `party'" ///
								  99 "Missing", modify 
lab val trichotomy_rev_`party' trichotomy_`party'
numlabel trichotomy_`party', add 

*<<< check coding of original trichotomy:
tab PartyLike_`party' trichotomy_rev_`party', m
table () (study_year) [aw=sample_weight] if study_year != 2002, stat(fvpercent trichotomy_rev_`party') missing

}

***************
* LEADERS:
***************
foreach party in cdu spd green fdp left afd {

*<<< generate revised trichotomy for each party:
recode LeaderLike_`party' (0/4 = 0) (5 = 1) (6/10 = 2) (-1 = .), gen(trichotomy_rev_`party'Leader)

*<<< label revised trichotomy for each party:
lab var trichotomy_rev_`party'Leader "Leader Likeability: `party' (revised trichotomy)"
lab def trichotomy_`party'Leader 0 "Does not like: `party' leader" ///
                                  1 "Neutral: `party' leader" ///
								  2 "Likes: `party' leader" ///
								  99 "Missing", modify 
lab val trichotomy_rev_`party'Leader trichotomy_`party'Leader
numlabel trichotomy_`party'Leader, add 

*<<< check coding of original trichotomy for each party:
tab LeaderLike_`party' trichotomy_rev_`party'Leader, m
table () (study_year) [aw=sample_weight] if study_year != 2002, stat(fvpercent trichotomy_rev_`party'Leader) missing

}

***
* NOTE: Graph created in Excel based on the above output.
***

***************
* VERIFICATION OF NUMBERS IN STATA TO VERIFY NUMBERS IN FIGURE F1:
***************

foreach party in cdu spd green fdp left afd {
	*<<< for each party, create dummy for respondents disliking party: 
	gen dislikes`party' = 1 if trichotomy_rev_`party' == 0 
	replace dislikes`party' = 0 if inlist(trichotomy_rev_`party', 1, 2)
	
	*<<< for each party, create dummy for respondents disliking leader: 
	gen dislikesleader`party' = 1 if trichotomy_rev_`party'Leader == 0
	replace dislikesleader`party' = 0 if inlist(trichotomy_rev_`party'Leader, 1, 2)
}


*<<< collapsing all party and leader dislike dummies with their mean 
*<<< (i.e., % of respondents disliking party/leader) by election year:
collapse (mean) dislikes* [aw=sample_weight], by(study_year)


foreach party in cdu spd green fdp left afd {
	*<<< for each party, create a "diff_*" variable subtracting % of leader-dislikers from 
	*<<< party dislikers:
	gen diff_`party' = round(((dislikes`party' - dislikesleader`party')*100), .01)
	display ""
	display"`party'"
	*<<< for each party, display results by election year:
	table () (study_year), stat(mean diff_`party') missing
}

*<<< change the frame back to default, with the whole dataset loaded 
frame change default 

*<<< drop the frame for verification of Figure F1:
frame drop tricho_rev_totals


********************************************************************************
**// FIGURE F2 - PARTY-LEADER POPULARITY INDEX INCLUDING MISSINGS IN CALCULATION:
********************************************************************************

*<<< creating a new frame "tricho_miss_totals" that includes the same data as the default frame: 
frame copy default tricho_miss_totals

*<<< switch to "tricho_miss_totals" frame:
frame change tricho_miss_totals

*<<< Creating trichotomies (dislike, neutral, like) for all parties and leaders:

***************
* PARTIES:
***************

foreach party in cdu spd green fdp left afd {

*<<< generate original trichotomy for each party:
recode PartyLike_`party' (0/3 = 0) (4/6 = 1) (7/10 = 2) (-1  = .), gen(trichotomy_orig_`party')

*<<< label original trichotomy:
lab var trichotomy_orig_`party' "Party Likeability: `party' (trichotomy)"
lab def trichotomy_`party' 0 "Does not like: `party'" ///
                                  1 "Neutral: `party'" ///
								  2 "Likes: `party'" ///
								  99 "Missing", modify 
lab val trichotomy_orig_`party' trichotomy_`party'
numlabel trichotomy_`party', add 

*<<< check coding of original trichotomy:
tab PartyLike_`party' trichotomy_orig_`party', m

table () (study_year) [aw=sample_weight] if study_year != 2002, stat(fvpercent trichotomy_orig_`party') missing
}

***************
* LEADERS
***************

foreach party in cdu spd green fdp left afd {

*<<< generate original trichotomy:
recode LeaderLike_`party' (0/3 = 0) (4/6 = 1) (7/10 = 2) (-1 . = 99), gen(trichotomy_orig_`party'Leader)

*<<< label original trichotomy:
lab var trichotomy_orig_`party'Leader "Leader Likeability: `party' (trichotomy)"
lab def trichotomy_`party'Leader 0 "Does not like: `party' leader" ///
                                  1 "Neutral: `party' leader" ///
								  2 "Likes: `party' leader" ///
								  99 "Missing", modify 
lab val trichotomy_orig_`party'Leader trichotomy_`party'Leader
numlabel trichotomy_`party'Leader, add 

*<<< check coding of original trichotomy:
tab LeaderLike_`party' trichotomy_orig_`party'Leader, m

table () (study_year) [aw=sample_weight] if study_year != 2002, stat(fvpercent trichotomy_orig_`party'Leader) missing

}

***
* NOTE: Graph created in Excel based on the above output.
***

***************
* VERIFICATION OF NUMBERS IN STATA TO VERIFY NUMBERS IN FIGURE F2:
***************

foreach party in cdu spd green fdp left afd {
	*<<< for each party, create dummy for respondents disliking party (missings included in 0): 
	gen dislikes`party' = 1 if trichotomy_orig_`party' == 0 
	replace dislikes`party' = 0 if dislikes`party' == .
	
	*<<< for each party, create dummy for respondents disliking leader (missings included in 0): 
	gen dislikesleader`party' = 1 if trichotomy_orig_`party'Leader == 0
	replace dislikesleader`party' = 0 if dislikesleader`party' == .
}

*<<< collapsing all party and leader dislike dummies with their mean 
*<<< (i.e., % of respondents disliking party/leader) by election year:
collapse (mean) dislikes* [aw=sample_weight], by(study_year)

foreach party in cdu spd green fdp left afd {
	*<<< for each party, create a "diff_*" variable subtracting % of leader-dislikers from 
	*<<< party dislikers:
	gen diff_`party' = round(((dislikes`party' - dislikesleader`party')*100), .01)
	display ""
	display"`party'"
	*<<< for each party, display results by election year:
	table () (study_year), stat(mean diff_`party') missing
}

*<<< change the frame back to default, with the whole dataset loaded 
frame change default 

*<<< drop the frame for verification of Figure F2:
frame drop tricho_miss_totals


********************************************************************************
**// TABLE F2 - SOCIODEMOGRAPHIC MODEL FOR 2021:
********************************************************************************

*<<< Table F2 - Multinomial logit for 2021 election - sociodemographics only: 
eststo F2 : mlogit vote_all ib5.typesofvoter female age university church_attendance east if study_year == 2021 [pweight=sample_weight], baseoutcome(1) // Union as reference


*<<< Create nicely formatted results table & export it to Output folder:
esttab F2 using "./Outputs/Stata Tables/tableF2.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table F2) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


********************************************************************************
**// FIGURES F3 & F4 - PREDICTED PROBABILITIES FOR MODEL IN TABLE F2 
********************************************************************************  

* <<< run model from Table F2
mlogit vote_all ib5.typesofvoter female age university church_attendance east if study_year == 2021 [pweight=sample_weight], baseoutcome(1) // Union as reference
fitstat

estat ic 

* <<< calculate marginal effects
margins, at(typesofvoter=(1(1)6)) 

* <<< create plot:
marginsplot, legend(off) ///
plot1opts(color(black)) ci1opt(color(black)) ///
plot2opts(color(maroon)) ci2opt(color(maroon)) ///
plot3opts(color(dkorange)) ci3opt(color(dkorange)) ///
plot4opts(color(forest_green)) ci4opt(color(forest_green)) ///
plot5opts(color(pink)) ci5opt(color(pink)) ///
plot6opts(color(midblue)) ci6opt(color(midblue)) ///
ysize(25) xsize(15) recast(scatter)  xlabel(, angle(vertical)) ///
addplot((hist typesofvoter,  color(gs12) discrete fraction width(.5)), below)  ///
graphregion(color(gs15)) ///
ytitle("Predicted Probabilities for Vote Choice" "(Point Estimates with 95% CIs)") ///
xtitle("") r1title("Histogram of Voter Types" "(Grey Bars)", size(medsmall)) ///
title("Predicted Probabilities of Vote Choice in 2021" "Election - Sociodemographics Only Model") ///
subtitle("(CDU, SPD, Greens, FDP)") 
*<<< graph exported via graph editor with the following changes made:
* Figure 3: manually drop Linke & AfD from the plot
* Figure 4: manually drop CDU, SPD, Greens and AfD from the plot, adopting subtitle


********************************************************************************
**// TABLE F3 - MODEL WITH PARTY ID CONTROL FOR 2021:
********************************************************************************

*<<< Table F3 - Model with Party ID Control for 2021:
eststo F3 : mlogit vote_all ib5.typesofvoter female age university church_attendance east ///
lr_self pid_spd pid_fdp pid_green pid_left pid_afd if study_year == 2021 [pweight=sample_weight], baseoutcome(1) // Union as reference
fitstat
estat ic 

*<<< Create nicely formatted results table & export it to Output folder:
esttab F3 using "./Outputs/Stata Tables/tableF3.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table F3) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") collab(none) mlabels(none) ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace

	   
********************************************************************************
**// FIGURES F5 & F6 - PREDICTED PROBABILITIES FOR MODEL IN TABLE F3
********************************************************************************  

* <<< Run model from table F3 
mlogit vote_all ib5.typesofvoter female age university church_attendance east ///
lr_self pid_spd pid_fdp pid_green pid_left pid_afd if study_year == 2021 [pweight=sample_weight], baseoutcome(1) // Union as reference
fitstat
estat ic 

* <<< calculate marginal effects	   
margins, at(typesofvoter=(1(1)6)) 

* <<< create plot:
marginsplot, legend(off) ///
plot1opts(color(black)) ci1opt(color(black)) ///
plot2opts(color(maroon)) ci2opt(color(maroon)) ///
plot3opts(color(dkorange)) ci3opt(color(dkorange)) ///
plot4opts(color(forest_green)) ci4opt(color(forest_green)) ///
plot5opts(color(pink)) ci5opt(color(pink)) ///
plot6opts(color(midblue)) ci6opt(color(midblue)) ///
ysize(25) xsize(15) recast(scatter)  xlabel(, angle(vertical)) ///
addplot((hist typesofvoter,  color(gs12) discrete fraction width(.5)), below)  ///
graphregion(color(gs15)) ///
ytitle("Predicted Probabilities for Vote Choice" "(Point Estimates with 95% CIs)") ///
xtitle("") r1title("Histogram of Voter Types" "(Grey Bars)", size(medsmall)) ///
title("Predicted Probabilities of Vote Choice in 2021" "Election - Model Including Party IDs") ///
subtitle("(CDU, SPD, Greens, FDP)") 
*<<< graph exported via graph editor with the following changes made:
* Figure 5: manually drop Linke & AfD from the plot
* Figure 6: manually drop CDU, SPD, Greens and AfD from the plot, adopting subtitle


********************************************************************************
**// TABLE F4 - MODEL WITH NUANCED VOTER TYPES FOR WEAK & STRONG LEANERS FOR 2021:
********************************************************************************

*<<< Generate distance measures between maximum party and leader evaluation for 
*<<< each respondent: 

********
*<<< Step 1: Obtain maximum value across all PARTY likability variables:
********

*<<< selects maximum value from party likability scores:
egen partymax = rowmax(PartyLike_cdu PartyLike_spd PartyLike_green PartyLike_fdp PartyLike_left PartyLike_afd) 

*<<< counts number of parties the maximum value was assigned to for exclusion of straightliners: 
gen partymaxcount = 0 

foreach party in cdu spd green fdp left afd {
	replace partymaxcount = partymaxcount + (PartyLike_`party' == partymax) if !inlist(partymax, -1, .)
}

*<<< Exclude straightliners (Rs that assigned all parties the same score):
foreach var of varlist partymax* {
replace `var' = . if (partymaxcount == 5 & inrange(study_year, 1998, 2009)) | ///
(partymaxcount == 6 & inrange(study_year, 2013, 2021))

replace `var' = . if partymaxcount > 2 | partymaxcount == 0

}


********
*<<< Step 2: Obtain maximum value across all LEADER likability variables:
********

*<<< selects maximum value from party likability scores:
egen leadermax = rowmax(LeaderLike_cdu LeaderLike_spd LeaderLike_green LeaderLike_fdp LeaderLike_left LeaderLike_afd)


*<<< counts number of leaders the maximum value was assigned to for exclusion of straightliners:
gen leadermaxcount = 0 

foreach leader in cdu spd green fdp left afd {
	replace leadermaxcount = leadermaxcount + (LeaderLike_`leader' == leadermax) if !inlist(leadermax, -1, .)
}


*<<< Exclude straightliners (Rs that assigned all leaders the same score):
foreach var of varlist leadermax* {
replace `var' = . if (leadermaxcount == 5 & inrange(study_year, 1998, 2013)) | ///
(leadermaxcount == 6 & inrange(study_year, 2017, 2021)) 

replace `var' = . if leadermaxcount > 2 | leadermaxcount == 0
}


********
*<<< Step 3: Subtract maximum party from maximum leader evaluation:
********

gen fav_leader_distance = leadermax - partymax if leadermax != . & partymax != .

********
*<<< Generate nuanced type of voter variable with subgroups for leaners:
********

gen typesofvoter_subtypes = .
replace typesofvoter_subtypes = 1 if typesofvoter == 1 // 1. Leader inclined voters
replace typesofvoter_subtypes = 2 if typesofvoter == 2 & inrange(fav_leader_distance, 2, 10) // 2. Strong leader leaning
replace typesofvoter_subtypes = 3 if typesofvoter == 2 & fav_leader_distance == 1 // 3. Weak leader leaning
replace typesofvoter_subtypes = 4 if typesofvoter == 3 // 4. Party & leader inclined
replace typesofvoter_subtypes = 5 if typesofvoter == 4 & fav_leader_distance == -1 // 5. Weak party leaning
replace typesofvoter_subtypes = 6 if typesofvoter == 4 & fav_leader_distance < -1 // 6. Strong party leaning
replace typesofvoter_subtypes = 7 if typesofvoter == 5 // 7. Party inclined
replace typesofvoter_subtypes = 8 if typesofvoter == 6 // 8. Incongruent voters


*<<< Create value labels for new nuanced subtype variable:
lab def subtypes_lab   1 "1. Leader inclined" ///
                       2 "2. Strong leader leaning" ///
					   3 "3. Weak leader leaning" ///
					   4 "4. Party & leader" ///
					   5 "5. Weak party leaning" ///
					   6 "6. Strong party leaning" ///
                       7 "7. Party inclined" ///         
                       8 "8. Incongruent", modify


*<<< Assign value labels to new nuanced subtype variable:
lab val typesofvoter_subtypes subtypes_lab

*<<< Check coding of new nuanced subtype variable:
bysort typesofvoter: fre typesofvoter_subtypes


********
* Table F4 - Model with Nuanced Voter Types for 2021: 
********

*<<< Table F4 - Model with Nuanced Voter Types for 2021: 
eststo F4 : mlogit vote_all ib7.typesofvoter_subtypes female age university church_attendance east lr_self if study_year == 2021 [pweight=sample_weight], baseoutcome(1) // Union as reference
fitstat

*<<< Create nicely formatted results table & export it to Output folder:
esttab F4 using "./Outputs/Stata Tables/tableF4.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table F4) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


********************************************************************************
**// FIGURES F7 & F8 - PREDICTED PROBABILITIES FOR MODEL IN TABLE F4
********************************************************************************  

*<<< running model from Table F4: 
mlogit vote_all ib7.typesofvoter_subtypes female age university church_attendance east lr_self if study_year == 2021 [pweight=sample_weight], baseoutcome(1) // Union as reference
fitstat

estat ic 

*<<< calculate marginal effects:
margins, at(typesofvoter=(1(1)8)) 

*<<< creating plot:
marginsplot, legend(off) ///
plot1opts(color(black)) ci1opt(color(black)) ///
plot2opts(color(maroon)) ci2opt(color(maroon)) ///
plot3opts(color(dkorange)) ci3opt(color(dkorange)) ///
plot4opts(color(forest_green)) ci4opt(color(forest_green)) ///
plot5opts(color(pink)) ci5opt(color(pink)) ///
plot6opts(color(midblue)) ci6opt(color(midblue)) ///
ysize(25) xsize(15) recast(scatter)  xlabel(, angle(vertical)) ///
addplot((hist typesofvoter_subtypes,  color(gs12) discrete fraction width(.5)), below)  ///
graphregion(color(gs15)) ///
ytitle("Predicted Probabilities for Vote Choice" "(Point Estimates with 95% CIs)") ///
xtitle("") r1title("Histogram of Voter Types" "(Grey Bars)", size(medsmall)) ///
title("Predicted Probabilities of Vote Choice in 2021" "Election for Nuanced Voter Type Variable") ///
subtitle("(CDU, SPD, Greens, FDP)") 
*<<< graph exported via graph editor with the following changes made:
* Figure 7 & 8: specify x-range: 1 - 8 in increments of 1 (drop the 0 from the graph)
* Figure F7: manually drop Linke & AfD from the plot
* Figure F8: manually drop CDU, SPD, FDP and Greens from the plot


********************************************************************************
**// FIGURE F9 - DISTRIBUTION OF VARIABLE MEASURING THE DIFFERENCE BETWEEN 
*                RESPONDENTS' MAXIMUM PARTY AND LEADER EVALUATION 
********************************************************************************  

*<<< creating graph:
graph twoway histogram fav_leader_distance, discrete /// 
      by(typesofvoter, ixaxes iytitle rows(3) ///
	  note("Positive values on x-axis indicate that R denoted leaders a higher maximum score than the parties." ///
	  , size(vsmall)) l1title("")) ///
	  xtitle("Distance between Highest Leader- and Party Rating", size(small)) ///
	  scheme(plotplain)  ///
	  ysize(6) xsize(4.5)

*<<< exporting graph:
graph export "./Outputs/Stata Graphs/FigureF9.png", as(png) name(Graph) replace


********************************************************************************
**// FIGURE F10 - DESCRIPTIVE INDEX BY PARTY FOR 1998 ELECTION
******************************************************************************** 

bysort typesofvoter: tab vote_pl [aw=sample_weight] if study_year == 1998 

***
* NOTE: Graph created in Excel based on the above numeric output.
***


********************************************************************************
**// FIGURE F11 - DESCRIPTIVE INDEX BY PARTY FOR 2005 ELECTION
******************************************************************************** 

bysort typesofvoter: tab vote_pl [aw=sample_weight] if study_year == 2005

***
* NOTE: Graph created in Excel based on the above numeric output.
***


********************************************************************************
**// FIGURE F12 - DESCRIPTIVE INDEX BY PARTY FOR 2009 ELECTION
******************************************************************************** 

bysort typesofvoter: tab vote_pl [aw=sample_weight] if study_year == 2009

***
* NOTE: Graph created in Excel based on the above numeric output.
***


********************************************************************************
**// FIGURE F13 - DESCRIPTIVE INDEX BY PARTY FOR 2009 ELECTION
******************************************************************************** 

bysort typesofvoter: tab vote_pl [aw=sample_weight] if study_year == 2013

***
* NOTE: Graph created in Excel based on the above numeric output.
***


********************************************************************************
**// FIGURE F14 - DESCRIPTIVE INDEX BY PARTY FOR 2017 ELECTION
******************************************************************************** 

bysort typesofvoter: tab vote_pl [aw=sample_weight] if study_year == 2017

***
* NOTE: Graph created in Excel based on the above numeric output.
***


********************************************************************************
**// FIGURE F15 - IMPACT OF VOTER TYPES ON PARTY VOTE - FIGURE 4 WITH LEFT & AFD
******************************************************************************** 

*<<< numbers for grey histogram in Figure F15: 
tab typesofvoter if study_year == 2021

*<<< multinomial logit as reported in Table E1.1: 
mlogit vote_all ib5.typesofvoter female age university church_attendance east lr_self if study_year == 2021 [pweight=sample_weight], baseoutcome(1) // Union as reference

fitstat
estat ic 

*<<< calculating marginal effects:
margins, at(typesofvoter=(1(1)6)) 

***
* NOTE: Graph created in Excel based on the above numeric output.
***


********************************************************************************
**// TABLE F5 - MULTINOMIAL FOR 1998 - IMPACT OF VOTER TYPES ON PARTY VOTE
******************************************************************************** 

*<<< multinomial logit as reported in Table F5: 
eststo F5 : mlogit vote_all ib5.typesofvoter female age university church_attendance east lr_self if study_year == 1998 [pweight=sample_weight], baseoutcome(1)
fitstat
estat ic 

*<<< Create nicely formatted results table & export it to Output folder:
esttab F5 using "./Outputs/Stata Tables/tableF5.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table F5) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


********************************************************************************
**// FIGURE F16 - IMPACT OF VOTER TYPES ON PARTY VOTE - 1998
******************************************************************************** 

*<<< numbers for grey histogram in Figure F16: 
tab typesofvoter if study_year == 1998

*<<< multinomial logit as reported in Table F5: 
mlogit vote_all ib5.typesofvoter female age university church_attendance east lr_self if study_year == 1998 [pweight=sample_weight], baseoutcome(1)

*<<< calculating marginal effects:
margins, at(typesofvoter=(1(1)6)) 

***
* NOTE: Graph created in Excel based on the above numeric output.
***


********************************************************************************
**// TABLE F6 - MULTINOMIAL FOR 2005 - IMPACT OF VOTER TYPES ON PARTY VOTE
******************************************************************************** 

*<<< multinomial logit as reported in Table F6: 
eststo F6 : mlogit vote_all ib5.typesofvoter female age university church_attendance east lr_self if study_year == 2005 [pweight=sample_weight], baseoutcome(1)
fitstat
estat ic 

*<<< Create nicely formatted results table & export it to Output folder:
esttab F6 using "./Outputs/Stata Tables/tableF6.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table F6) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


********************************************************************************
**// FIGURE F17 - IMPACT OF VOTER TYPES ON PARTY VOTE - 2005
******************************************************************************** 

*<<< numbers for grey histogram in Figure F17: 
tab typesofvoter if study_year == 2005

*<<< multinomial logit as reported in Table F6: 
mlogit vote_all ib5.typesofvoter female age university church_attendance east lr_self if study_year == 2005 [pweight=sample_weight], baseoutcome(1)

*<<< calculating marginal effects:
margins, at(typesofvoter=(1(1)6)) 

***
* NOTE: Graph created in Excel based on the above numeric output.
***


********************************************************************************
**// TABLE F7 - MULTINOMIAL FOR 2009 - IMPACT OF VOTER TYPES ON PARTY VOTE
******************************************************************************** 

*<<< multinomial logit as reported in Table F7: 
eststo F7 : mlogit vote_all ib5.typesofvoter female age university church_attendance east lr_self if study_year == 2009 [pweight=sample_weight], baseoutcome(1)
fitstat
estat ic 

*<<< Create nicely formatted results table & export it to Output folder:
esttab F7 using "./Outputs/Stata Tables/tableF7.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table F7) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


********************************************************************************
**// FIGURE F18 - IMPACT OF VOTER TYPES ON PARTY VOTE - 2009
******************************************************************************** 

*<<< numbers for grey histogram in Figure F18: 
tab typesofvoter if study_year == 2009

*<<< multinomial logit as reported in Table F7: 
mlogit vote_all ib5.typesofvoter female age university church_attendance east lr_self if study_year == 2009 [pweight=sample_weight], baseoutcome(1)

*<<< calculating marginal effects:
margins, at(typesofvoter=(1(1)6)) 

***
* NOTE: Graph created in Excel based on the above numeric output.
***


********************************************************************************
**// TABLE F8 - MULTINOMIAL FOR 2013 - IMPACT OF VOTER TYPES ON PARTY VOTE
******************************************************************************** 

*<<< multinomial logit as reported in Table F8: 
eststo F8 : mlogit vote_all ib5.typesofvoter female age university church_attendance east lr_self if study_year == 2013 [pweight=sample_weight], baseoutcome(1)
fitstat
estat ic 

*<<< Create nicely formatted results table & export it to Output folder:
esttab F8 using "./Outputs/Stata Tables/tableF8.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table F8) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


********************************************************************************
**// FIGURE F19 - IMPACT OF VOTER TYPES ON PARTY VOTE - 2013
******************************************************************************** 

*<<< numbers for grey histogram in Figure F19: 
tab typesofvoter if study_year == 2013

*<<< multinomial logit as reported in Table F8: 
mlogit vote_all ib5.typesofvoter female age university church_attendance east lr_self if study_year == 2013 [pweight=sample_weight], baseoutcome(1)

*<<< calculating marginal effects:
margins, at(typesofvoter=(1(1)6)) 

***
* NOTE: Graph created in Excel based on the above numeric output.
***


********************************************************************************
**// TABLE F9 - MULTINOMIAL FOR 2017 - IMPACT OF VOTER TYPES ON PARTY VOTE
******************************************************************************** 

*<<< multinomial logit as reported in Table F9: 
eststo F9 : mlogit vote_all ib5.typesofvoter female age university church_attendance east lr_self if study_year == 2017 [pweight=sample_weight], baseoutcome(1)
fitstat
estat ic 

*<<< Create nicely formatted results table & export it to Output folder:
esttab F9 using "./Outputs/Stata Tables/tableF9.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table F9) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


********************************************************************************
**// FIGURE F20 - IMPACT OF VOTER TYPES ON PARTY VOTE - 2017
******************************************************************************** 

*<<< numbers for grey histogram in Figure F20: 
tab typesofvoter if study_year == 2017

*<<< multinomial logit as reported in Table F9: 
mlogit vote_all ib5.typesofvoter female age university church_attendance east lr_self if study_year == 2017 [pweight=sample_weight], baseoutcome(1)

*<<< calculating marginal effects:
margins, at(typesofvoter=(1(1)6)) 

***
* NOTE: Graph created in Excel based on the above numeric output.
***


********************************************************************************
**// TABLE F10 - MULTINOMIAL FOR 1998-2021 - IMPACT OF VOTER TYPES ON PARTY VOTE
******************************************************************************** 

*<<< multinomial logit as reported in Table F10: 
eststo F10 : mlogit vote_all ib5.typesofvoter ib2021.study_year female age university church_attendance east lr_self [pweight=sample_weight], baseoutcome(1)
fitstat
estat ic 

*<<< Create nicely formatted results table & export it to Output folder:
esttab F10 using "./Outputs/Stata Tables/tableF10.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table F10) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace



********************************************************************************
**// TABLE F11 - MULTINOMIAL FOR 1998 - IMPACT OF VOTER TYPES & PARTY ID ON PARTY VOTE
******************************************************************************** 

*<<< multinomial logit as reported in Table F11: 
eststo F11 : mlogit vote_all ib5.typesofvoter female age university church_attendance east pid_spd pid_green pid_left if study_year == 1998 [pweight=sample_weight], baseoutcome(1)
fitstat
estat ic 

*<<< Create nicely formatted results table & export it to Output folder:
esttab F11 using "./Outputs/Stata Tables/tableF11.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table F11) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


********************************************************************************
**// TABLE F12 - MULTINOMIAL FOR 2005 - IMPACT OF VOTER TYPES & PARTY ID ON PARTY VOTE
******************************************************************************** 

*<<< multinomial logit as reported in Table F12: 
eststo F12 : mlogit vote_all ib5.typesofvoter female age university church_attendance east pid_spd pid_green pid_fdp pid_left if study_year == 2005 [pweight=sample_weight], baseoutcome(1)
fitstat
estat ic 

*<<< Create nicely formatted results table & export it to Output folder:
esttab F12 using "./Outputs/Stata Tables/tableF12.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table F12) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace

	   
********************************************************************************
**// TABLE F13 - MULTINOMIAL FOR 2009 - IMPACT OF VOTER TYPES & PARTY ID ON PARTY VOTE
******************************************************************************** 

*<<< multinomial logit as reported in Table F13: 
eststo F13 : mlogit vote_all ib5.typesofvoter female age university church_attendance east pid_spd pid_green pid_fdp pid_left if study_year == 2009 [pweight=sample_weight], baseoutcome(1)
fitstat
estat ic 

*<<< Create nicely formatted results table & export it to Output folder:
esttab F13 using "./Outputs/Stata Tables/tableF13.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table F13) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


********************************************************************************
**// TABLE F14 - MULTINOMIAL FOR 2013 - IMPACT OF VOTER TYPES & PARTY ID ON PARTY VOTE
******************************************************************************** 

*<<< multinomial logit as reported in Table F14: 
eststo F14 : mlogit vote_all ib5.typesofvoter female age university church_attendance east pid_spd pid_green pid_fdp if study_year == 2013 [pweight=sample_weight], baseoutcome(1)
fitstat
estat ic 

*<<< Create nicely formatted results table & export it to Output folder:
esttab F14 using "./Outputs/Stata Tables/tableF14.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table F14) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


********************************************************************************
**// TABLE F15 - MULTINOMIAL FOR 2017 - IMPACT OF VOTER TYPES & PARTY ID ON PARTY VOTE
******************************************************************************** 

*<<< multinomial logit as reported in Table F15: 
eststo F15 : mlogit vote_all ib5.typesofvoter female age university church_attendance east pid_spd pid_green pid_fdp pid_left pid_afd if study_year == 2017 [pweight=sample_weight], baseoutcome(1)
fitstat
estat ic 

*<<< Create nicely formatted results table & export it to Output folder:
esttab F15 using "./Outputs/Stata Tables/tableF15.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table F15) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace

	   
********************************************************************************
**// TABLE F16 - MULTINOMIAL FOR 2021 - IMPACT OF VOTER TYPES & PARTY ID ON PARTY VOTE
******************************************************************************** 

*<<< multinomial logit as reported in Table F16: 
eststo F16 : mlogit vote_all ib5.typesofvoter female age university church_attendance east pid_spd pid_green pid_fdp pid_left pid_afd if study_year == 2021 [pweight=sample_weight], baseoutcome(1)
fitstat
estat ic 

*<<< Create nicely formatted results table & export it to Output folder:
esttab F16 using "./Outputs/Stata Tables/tableF16.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table F16) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace

	   
********************************************************************************
**// TABLE F17 - MULTINOMIAL FOR 2021 - IMPACT OF VOTER TYPES & PARTY ID ON PARTY VOTE
******************************************************************************** 

*<<< multinomial logit as reported in Table F17: 
eststo F17 : mlogit vote_all ib5.typesofvoter female age university church_attendance east pid_spd pid_green pid_fdp pid_left ib2021.study_year [pweight=sample_weight], baseoutcome(1)
fitstat
estat ic 

*<<< Create nicely formatted results table & export it to Output folder:
esttab F17 using "./Outputs/Stata Tables/tableF17.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table F17) /// 
	   nobaselevels unstack noomitted ///
	   nonumbers  ///
	   eqlabels("SPD" "FDP" "Greens" "Left" "AfD") mtitles("") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


********************************************************************************
********************************************************************************
**#>>> 6: APPENDIX G - LOGIT MODELS (FOR 1998-2021 TIME SERIES DATA)
********************************************************************************
********************************************************************************
	   
********************************************************************************
**// TABLE G1 - LOGITS FOR 2021 - IMPACT OF VOTER TYPES ON PARTY VOTE
******************************************************************************** 
  
*<<< logits by party as reported in Table G1: 
foreach party in union spd green fdp left afd {
	eststo G1_`party': logit vote_`party' ib5.typesofvoter female age university church_attendance east lr_self if study_year == 2021 [pweight=sample_weight]
}

*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G1_* using "./Outputs/Stata Tables/tableG1.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G1) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke" "AfD") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


********************************************************************************
**// TABLE G3 - LOGITS FOR 2021 - IMPACT OF VOTER TYPES ON PARTY VOTE - SOCIODEM ONLY
******************************************************************************** 
  
*<<< logits by party as reported in Table G3: 
foreach party in union spd green fdp left afd {
	eststo G3_`party': logit vote_`party' ib5.typesofvoter female age university church_attendance east if study_year == 2021 [pweight=sample_weight]
}

*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G3_* using "./Outputs/Stata Tables/tableG3.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G3) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke" "AfD") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace

	   
********************************************************************************
**// TABLE G4 - LOGITS FOR 2021 - IMPACT OF VOTER TYPES AND PARTY ID ON PARTY VOTE 
******************************************************************************** 

*<<< logit model for Union vote (based on party ID for CDU): 
eststo G4_union : logit vote_union ib5.typesofvoter /// 
                               female age university church_attendance east  ///
							   lr_self pid_cdu ///
							   if study_year == 2021 [pweight=sample_weight] 
  
*<<< logits by party as reported in Table G4: 
foreach party in spd green fdp left afd {
	eststo G4_`party': logit vote_`party' ib5.typesofvoter female age university church_attendance east lr_self pid_`party' if study_year == 2021 [pweight=sample_weight]
}

*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G4_* using "./Outputs/Stata Tables/tableG4.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G4) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke" "AfD") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


********************************************************************************
**// TABLE G5 - LOGITS FOR 2021 - IMPACT OF NUANCED VOTER TYPES ON PARTY VOTE 
******************************************************************************** 
    
*<<< logits by party as reported in Table G5: 
foreach party in union spd green fdp left afd {
	eststo G5_`party': logit vote_`party' ib7.typesofvoter_subtypes female age university church_attendance east lr_self if study_year == 2021 [pweight=sample_weight]
}

*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G5_* using "./Outputs/Stata Tables/tableG5.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G5) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke" "AfD") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


********************************************************************************
**// TABLE G6 - LOGITS FOR 1998 - IMPACT OF VOTER TYPES ON PARTY VOTE 
******************************************************************************** 
    
*<<< logits by party as reported in Table G6: 
foreach party in union spd green fdp left {
	eststo G6_`party': logit vote_`party' ib7.typesofvoter_subtypes female age university church_attendance east lr_self if study_year == 1998 [pweight=sample_weight]
}

*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G6_* using "./Outputs/Stata Tables/tableG6.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G6) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke" "AfD") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace
 
 
********************************************************************************
**// TABLE G7 - LOGITS FOR 2005 - IMPACT OF VOTER TYPES ON PARTY VOTE 
******************************************************************************** 
    
*<<< logits by party as reported in Table G7: 
foreach party in union spd green fdp left {
	eststo G7_`party': logit vote_`party' ib5.typesofvoter female age university church_attendance east lr_self if study_year == 2005 [pweight=sample_weight]
}

*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G7_* using "./Outputs/Stata Tables/tableG7.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G7) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke" "AfD") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace

	   
********************************************************************************
**// TABLE G8 - LOGITS FOR 2009 - IMPACT OF VOTER TYPES ON PARTY VOTE 
******************************************************************************** 
    
*<<< logits by party as reported in Table G8: 
foreach party in union spd green fdp left {
	eststo G8_`party': logit vote_`party' ib5.typesofvoter female age university church_attendance east lr_self if study_year == 2009 [pweight=sample_weight]
}

*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G8_* using "./Outputs/Stata Tables/tableG8.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G8) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke" "AfD") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace

	   
********************************************************************************
**// TABLE G9 - LOGITS FOR 2013 - IMPACT OF VOTER TYPES ON PARTY VOTE 
******************************************************************************** 
    
*<<< logits by party as reported in Table G9: 
foreach party in union spd green fdp left {
	eststo G9_`party': logit vote_`party' ib5.typesofvoter female age university church_attendance east lr_self if study_year == 2013 [pweight=sample_weight]
}

*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G9_* using "./Outputs/Stata Tables/tableG9.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G9) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke" "AfD") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


********************************************************************************
**// TABLE G10 - LOGITS FOR 2017 - IMPACT OF VOTER TYPES ON PARTY VOTE 
******************************************************************************** 
    
*<<< logits by party as reported in Table G10: 
foreach party in union spd green fdp left afd {
	eststo G10_`party': logit vote_`party' ib5.typesofvoter female age university church_attendance east lr_self if study_year == 2017 [pweight=sample_weight]
}

*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G10_* using "./Outputs/Stata Tables/tableG10.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G10) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke" "AfD") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace

	   
********************************************************************************
**// TABLE G11 - LOGITS FOR 1998-2021 - IMPACT OF VOTER TYPES ON PARTY VOTE 
******************************************************************************** 
    
*<<< logits by party as reported in Table G11: 
foreach party in union spd green fdp left {
	eststo G11_`party': logit vote_`party' ib5.typesofvoter female age university church_attendance east lr_self ib2021.study_year [pweight=sample_weight]
}

*<<< logit for AfD as reported in Table G11, as AfD data is only available for 2017 & 2021: 
eststo G11_afd : logit vote_afd ib5.typesofvoter /// 
                 female age university church_attendance east  ///
				 lr_self 2017.study_year [pweight=sample_weight] 

*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G11_* using "./Outputs/Stata Tables/tableG11.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G11) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke" "AfD") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


********************************************************************************
**// TABLE G12 - LOGITS FOR 1998 - IMPACT OF VOTER TYPES AND PARTY ID ON PARTY VOTE 
******************************************************************************** 

*<<< logit model for Union vote (based on party ID for CDU): 
eststo G12_union : logit vote_union ib5.typesofvoter /// 
                               female age university church_attendance east  ///
							   pid_cdu ///
							   if study_year == 1998 [pweight=sample_weight] 
 
*<<< logits by party as reported in Table G12: 
foreach party in spd green fdp left {
	eststo G12_`party': logit vote_`party' ib5.typesofvoter female age university church_attendance east pid_`party' if study_year == 1998 [pweight=sample_weight]
}

*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G12_* using "./Outputs/Stata Tables/tableG12.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G12) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace

	   
********************************************************************************
**// TABLE G13 - LOGITS FOR 2005 - IMPACT OF VOTER TYPES AND PARTY ID ON PARTY VOTE 
******************************************************************************** 

*<<< logit model for Union vote (based on party ID for CDU):  
eststo G13_union : logit vote_union ib5.typesofvoter /// 
                               female age university church_attendance east  ///
							   pid_cdu ///
							   if study_year == 2005 [pweight=sample_weight] 
 
*<<< logits by party as reported in Table G12: 
foreach party in spd green fdp left {
	eststo G13_`party': logit vote_`party' ib5.typesofvoter female age university church_attendance east pid_`party' if study_year == 2005 [pweight=sample_weight]
}

*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G13_* using "./Outputs/Stata Tables/tableG13.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G13) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace
	   

********************************************************************************
**// TABLE G14 - LOGITS FOR 2009 - IMPACT OF VOTER TYPES AND PARTY ID ON PARTY VOTE 
******************************************************************************** 

*<<< logit model for Union vote (based on party ID for CDU):
eststo G14_union : logit vote_union ib5.typesofvoter /// 
                               female age university church_attendance east  ///
							   pid_cdu ///
							   if study_year == 2009 [pweight=sample_weight] 
 
*<<< logits by party as reported in Table G12: 
foreach party in spd green fdp left {
	eststo G14_`party': logit vote_`party' ib5.typesofvoter female age university church_attendance east pid_`party' if study_year == 2009 [pweight=sample_weight]
}

*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G14_* using "./Outputs/Stata Tables/tableG14.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G14) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace

	   
********************************************************************************
**// TABLE G15 - LOGITS FOR 2013 - IMPACT OF VOTER TYPES AND PARTY ID ON PARTY VOTE 
******************************************************************************** 

*<<< logit model for Union vote (based on party ID for CDU):
eststo G15_union : logit vote_union ib5.typesofvoter /// 
                               female age university church_attendance east  ///
							   pid_cdu ///
							   if study_year == 2013 [pweight=sample_weight] 
 
*<<< logits by party as reported in Table G12: 
foreach party in spd green fdp left {
	eststo G15_`party': logit vote_`party' ib5.typesofvoter female age university church_attendance east pid_`party' if study_year == 2013 [pweight=sample_weight]
}

*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G15_* using "./Outputs/Stata Tables/tableG15.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G15) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace
	   

********************************************************************************
**// TABLE G16 - LOGITS FOR 2017 - IMPACT OF VOTER TYPES AND PARTY ID ON PARTY VOTE 
******************************************************************************** 
  
*<<< logits by party as reported in Table G16: 
foreach party in union spd green fdp left afd {
	eststo G16_`party': logit vote_`party' ib5.typesofvoter female age university church_attendance east pid_`party' if study_year == 2017 [pweight=sample_weight]
}

*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G16_* using "./Outputs/Stata Tables/tableG16.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G16) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke" "AfD") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace


	   
********************************************************************************
**// TABLE G17 - LOGITS FOR 2021 - IMPACT OF VOTER TYPES AND PARTY ID ON PARTY VOTE 
******************************************************************************** 

*<<< logit model for Union vote (based on party ID for CDU): 
eststo G17_union : logit vote_union ib5.typesofvoter /// 
                               female age university church_attendance east  ///
							   pid_cdu ///
							   if study_year == 2021 [pweight=sample_weight] 
 
* logits by party as reported in Table G17: 
foreach party in spd green fdp left afd {
	eststo G17_`party': logit vote_`party' ib5.typesofvoter female age university church_attendance east pid_`party' if study_year == 2021 [pweight=sample_weight]
}

*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G17_* using "./Outputs/Stata Tables/tableG17.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G17) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke" "AfD") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace

	   
	   
********************************************************************************
**// TABLE G18 - LOGITS FOR 1998-2021 - IMPACT OF VOTER TYPES AND PARTY ID ON PARTY VOTE 
******************************************************************************** 
 
*<<< generate common PID variable for CDU:
gen pid_union2 = pid_union if study_year == 2017
replace pid_union2 = pid_cdu if study_year != 2017
 
*<<< run model for CDU:
eststo G18_union : logit vote_union ib5.typesofvoter /// 
                               female age university church_attendance east  ///
							   pid_union2 ib2021.study_year [pweight=sample_weight] 
 
*<<< logits by party as reported in Table G18 for all other parties: 
foreach party in spd green fdp left {
	eststo G18_`party': logit vote_`party' ib5.typesofvoter female age university church_attendance east pid_`party' ib2021.study_year [pweight=sample_weight]
}

*<<< logit for AfD as reported in Table G11, as AfD data is only available for 2017 & 2021: 
eststo G18_afd : logit vote_afd ib5.typesofvoter /// 
                 female age university church_attendance east  ///
				 pid_afd 2017.study_year [pweight=sample_weight] 


*<<< Create nicely formatted results table with all logits & export it to Output folder:
esttab G18_* using "./Outputs/Stata Tables/tableG18.rtf", b(3) se(3) nogap ///
       star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(25) label title(Table G17) /// 
	   nobaselevels  ///
	   nonumbers mtitles("CDU" "SPD" "Greens" "FDP" "Linke" "AfD") ///
	   stats(N r2_p ll aic bic, labels("N" "Pseudo R^2" "Log likelihood" "AIC" "BIC")) ///
	   note("Source of data: GLES 2021 Post-Election Cross-Section.") replace

	   
*<<< drop all stored estimates from memory: 
eststo clear
	   
* END OF FILE
